<!--
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 * 		http://www.fckeditor.net/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: frmimageeditor.html
 * 	This page facilitates the editing of images.
 * 
 * File Authors:
 * 		Grant French (grant@mcpuk.net)
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<link href="browser.css" type="text/css" rel="stylesheet">
		<script type="text/javascript" src="js/fckxml.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/wz_jsgraphics.js"></script>
		<script type="text/javascript" src="js/EditorContent.js"></script>
		<script language="javascript" type="text/javascript">
<!--

oConnector.CurrentFolder = GetMyUrlParam( 'CurrentFolder' ) ;
var fileName=GetMyUrlParam( 'FileName' ) ;
var fileURL=unescape( GetMyUrlParam( 'FileURL' ) );

var cursor_X, cursor_Y;
var imageEditorLoaded=false;

var bottomFrame1, bottomFrame2, bottomFrame3;
/*
var t_cx, t_cy, t_cw, t_ch;
var m_sx, m_sy, m_w, m_h, m_a, m_d;
var s_sw, s_sh;

var r_ra;
var constrained;
var pattern = "images/2x2.gif";*/

function RenameFile( fileName, fileUrl )
{
	var promptMsg='Please enter the new name for ' + fileName + ':';
	var newName=prompt(promptMsg,fileName);
	
	if ((newName!=null)&&(newName!='')&&(newName!=fileName)) {
		oConnector.SendCommand( 'RenameFile', "FileName=" + escape( fileName ) + "&NewName=" + escape( newName ), RenameFileCallBack ) ;
	}
}

function RenameFolder( folderName )
{
	var promptMsg='Please enter the new name for ' + folderName + ':';
	var newName=prompt(promptMsg,folderName);
	
	if ((newName!=null)&&(newName!='')&&(newName!=folderName)) {
		oConnector.SendCommand( 'RenameFolder', "FolderName=" + escape( folderName ) + "&NewName=" + escape ( newName ), RenameFolderCallBack ) ;
	}
}

function LoadResources( resourceType, folderPath )
{
	oListManager.Clear() ;
	oConnector.ResourceType = resourceType ;
	oConnector.CurrentFolder = folderPath
	oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
}

function Refresh()
{
	LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;
}

function RenameFolderCallBack ( fckXml )
{
	var oNodes = fckXml.SelectNodes( 'Connector/Error' );
	if (oNodes.length>0) {
		var errNo = parseInt(oNodes[0].attributes.getNamedItem('number').value) ;
		
		switch (errNo) {
			case 0 :
				break;	
			
			case 602 :
				alert('Failed to rename folder.');
				break;
			
			default:
				alert('Invalid XML response from connector..');
		}
	} else {
		alert('Invalid XML response from connector.');
	}
	Refresh();
}


function drawFramework() 
{
	bottomFrame1 = top.frames['frmCreateFolder'].document;
	bottomFrame2 = top.frames['frmUpload'].document;
	bottomFrame3 = top.frames['frmFolders'].document;
	
	bottomFrame1.body.innerHTML='<table style="border-width: 0px; border-style: none;" align="center" cellpadding="2" id="toolbar1"><table>';
	bottomFrame2.body.innerHTML='<table style="height: 100%; border-width: 0px; border-style: none;" cellpadding="4"><tr id="toolbar2"></tr><table>';
	bottomFrame3.body.innerHTML='<table style="border-width: 0px; border-style: none;" align="center" cellpadding="8" id="toolbar3"><table>';
	
	var toolbar1 = bottomFrame1.getElementById('toolbar1');
	var toolbar2 = bottomFrame2.getElementById('toolbar2');
	var toolbar3 = bottomFrame3.getElementById('toolbar3');
	

/*#######################*/
/* START OF MAIN TOOLBAR */
/*#######################*/

	/* --- Save Image --- */
	var row = toolbar3.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = 	'<a href="" title="Save Image">' +
				'<img src="images/toolbar/save.gif" style="width: 22px; height: 22px;" /><br />' + 
				'Save' +
				'</a>';
	oCell.noWrap = true;
	oCell.align = 'center';
		
	
	/* --- Close Image --- */
	var row = toolbar3.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = 	'<a href="#" title="Close Image" onclick="window.top.location.reload();">' +
				'<img src="images/toolbar/close.gif" style="width: 22px; height: 22px;" /><br />' + 
				'Close' +
				'</a>';
	oCell.noWrap = true;
	oCell.align = 'center';
	
	
	/* --- Seperator --- */
	var row = toolbar3.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = 	'<hr /><br />';
				
	oCell.noWrap = true;
	oCell.align = 'center';
	
	
	/* --- Resize Image --- */
	var row = toolbar3.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = 	'<a href="javascript: top.frames[\'frmResourcesList\'].setMode(\'resize\');" class="tb_item" id="tb_scale" title="Resize Image">' +
				'<img src="images/toolbar/resize.gif" style="width: 22px; height: 22px;" /><br />' + 
				'Resize' +
				'</a>';
	oCell.noWrap = true;
	oCell.align = 'center';
	
	
	/* --- Crop Image --- */
	var row = toolbar3.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = 	'<a href="javascript: top.frames[\'frmResourcesList\'].setMode(\'crop\');" class="tb_item" id="tb_crop" title="Crop Image">' +
				'<img src="images/toolbar/crop.gif" style="width: 22px; height: 22px;" /><br />' + 
				'Crop' +
				'</a>';
	oCell.noWrap = true;
	oCell.align = 'center';
	
	
	/* --- Rotate Image --- */
	var row = toolbar3.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = 	'<a href="javascript: top.frames[\'frmResourcesList\'].setMode(\'rotate\');" class="tb_item" id="tb_rotate" title="Rotate Image">' +
				'<img src="images/toolbar/rotate.gif" style="width: 22px; height: 22px;" /><br />' + 
				'Rotate' +
				'</a>';
	oCell.noWrap = true;
	oCell.align = 'center';
	
	
	/* --- Flip Image --- */
	var row = toolbar3.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = 	'<a href="javascript: top.frames[\'frmResourcesList\'].setMode(\'flip\');" class="tb_item" id="tb_flip" title="Flip Image">' +
				'<img src="images/toolbar/flip.gif" style="width: 22px; height: 22px;" /><br />' + 
				'Flip' +
				'</a>';
	oCell.noWrap = true;
	oCell.align = 'center';
	
	

/*###################*/
/* START OF INFO BAR */
/*###################*/
	/* --- X Position --- */
	var row = toolbar1.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = '<div style="display: inline;">X: <div style="display: inline;" id="cursor_x">0</div>px</div>';
	oCell.noWrap = true;
	oCell.align = 'center';
	cursor_X=bottomFrame1.getElementById('cursor_x');
	
	/* --- Y Posision --- */
	var row = toolbar1.insertRow(-1);
	var oCell = row.insertCell(-1);
	oCell.innerHTML = '<div style="display: inline;">Y: <div style="display: inline;" id="cursor_y">0</div>px</div>';
	oCell.noWrap = true;
	oCell.align = 'center';
	cursor_Y=bottomFrame1.getElementById('cursor_y');

	
/*#####################*/
/* START OF MANUAL BAR */
/*#####################*/

	/* --- X Position --- */
	//var row = toolbar2.insertRow(-1);
	var oCell = toolbar2.insertCell(-1);
	oCell.innerHTML = '<input type="text" id="cx" />' + 
	'<input type="text" id="cy" />';
	
	oCell.noWrap = true;
	oCell.align = 'center';
	cursor_X=bottomFrame1.getElementById('cursor_x');


}

window.onload = function()
{
	drawFramework();
	document.getElementById('theImage').src=fileURL;
	
	jg_doc = new jsGraphics("imgCanvas"); // draw directly into document
	jg_doc.setColor("#000000"); // black
	
// 	top.frames['frmResourcesList'].setMode('scale');
	imageEditorLoaded=true;
// 	top.frames['frmResourcesList'].setMode('scale');
}

function updateXY(eventObject)
{
	if (imageEditorLoaded) {
		cursor_X.innerHTML = eventObject.pageX;
		cursor_Y.innerHTML = eventObject.pageY;
	}
}

//-->

		</script>
		<style type="text/css">
			body { margin: 0; padding: 0;  background-color: #eee; }
			table { width: 100%; }
			table td { text-align: center; }
			.crop{cursor:crosshair;}
			.selection { border: dotted 1px #000000; position:absolute; width: 0px; height: 1px; z-index:5; }
			.selectionWhite{ border: dotted 1px #FFFFFF; position:absolute; width: 0px; height: 1px; z-index:5; }
			.handleBox{ z-index:105; }
			.error { font-size:large; font-weight:bold; color:#c00; font-family: Helvetica, sans-serif; } 
		</style>
	</head>
	<body class="FileArea" bottomMargin="10" leftMargin="10" topMargin="10" rightMargin="10">
		<div id="status"></div>
		<div id="ant" class="selection" style="visibility:hidden"><img src="img/spacer.gif" width="0" height="0" border="0" alt="" id="cropContent"></div>
		<br /><table style="margin-left: auto; margin-right: auto;">
			<tr>
				<td>
					<span id="imgCanvas" class="crop"><img src="" alt="" id="theImage" name="theImage"></span>
				</td>
			</tr>
		</table>
	</body>
</html>
